package com.hwadeefsc.springboot.service.impl;

import com.hwadeefsc.springboot.dao.SchoolInfoDao;
import com.hwadeefsc.springboot.entity.SchoolInfo;
import com.hwadeefsc.springboot.service.SchoolInfoService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;
import java.util.List;

/**
 * (SchoolInfo)表服务实现类
 *
 * @author makejava
 * @since 2024-07-09 21:43:27
 */
@Service("schoolInfoService")
public class SchoolInfoServiceImpl implements SchoolInfoService {
    @Resource
    private SchoolInfoDao schoolInfoDao;

    /**
     * 通过ID查询单条数据
     *
     * @param infoId 主键
     * @return 实例对象
     */
    @Override
    public SchoolInfo queryById(Integer infoId) {
        return this.schoolInfoDao.queryById(infoId);
    }

    /**
     * 分页查询
     *
     * @param schoolInfo 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<SchoolInfo> queryByPage(SchoolInfo schoolInfo, PageRequest pageRequest) {
        long total = this.schoolInfoDao.count(schoolInfo);
        return new PageImpl<>(this.schoolInfoDao.queryAllByLimit(schoolInfo, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param schoolInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SchoolInfo insert(SchoolInfo schoolInfo) {
        this.schoolInfoDao.insert(schoolInfo);
        return schoolInfo;
    }

    /**
     * 修改数据
     *
     * @param schoolInfo 实例对象
     * @return 实例对象
     */
    @Override
    public SchoolInfo update(SchoolInfo schoolInfo) {
        this.schoolInfoDao.update(schoolInfo);
        return this.queryById(schoolInfo.getInfoId());
    }

    /**
     * 通过主键删除数据
     *
     * @param infoId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer infoId) {
        return this.schoolInfoDao.deleteById(infoId) > 0;
    }

    @Override
    public List<SchoolInfo> queryAll() {
        return  this.schoolInfoDao.getALLSchoolInfo();
    }
}
